<template>
  <div class="universityManage">
     <el-form ref="searchForm" :model="searchForm" label-width="20px">
       <el-row gutter="20">
         <div v-if="GLOBAL.global_limit.includes('7')">
           <el-col :span="2" offset="0" >
             <el-button type="primary" size="mini" @click=addChoose>创建高校</el-button>
           </el-col>
         </div>
         <div v-if="GLOBAL.global_limit.includes('6')">
           <el-col :span="4" offset="4">
             <el-input v-model="queryInfo.universityName" width="80px" size="small" suffix-icon="el-icon-search" clearable placeholder="请输入高校名称"></el-input>
           </el-col>
           <el-col :span="3">
             <el-select  v-model="queryInfo.universityDirector" size="small" filterable clearable placeholder="请选择负责人">
               <el-option
                 v-for="item in directorList"
                 :key="item"
                 :label="item"
                 :value="item"/>
             </el-select>
           </el-col>
<!--           <el-col :span="3">-->
<!--             <el-select v-model="queryInfo.universityStatus" size="small" filterable clearable placeholder="请选择高校状态">-->
<!--               <el-option-->
<!--                 v-for="item in statusList"-->
<!--                 :key="item.value"-->
<!--                 :label="item.label"-->
<!--                 :value="item.value"/>-->
<!--             </el-select>-->
<!--           </el-col>-->
           <el-col :span="7">
             <el-date-picker
               v-model="queryInfo.filterDates"
               type="daterange"
               value-format="yyyy-MM-dd"
               align="left"
               size="small"
               unlink-panels
               range-separator="至"
               start-placeholder="开始日期"
               end-placeholder="结束日期">
             </el-date-picker>
           </el-col>
           <el-col :span="2" >
             <el-button type="primary" size="mini" @click="initData">搜索</el-button>
           </el-col>
         </div>
       </el-row>
     </el-form>
     <el-dialog title="新建高校信息" align="left" :visible.sync="dialogFormVisible">
      <el-form :model="addInfo" label-width="100px">
        <el-form-item label="高校名称" >
          <el-input v-model="addInfo.universityName" ></el-input>
        </el-form-item>
        <el-form-item label="高校地址" >
          <el-input v-model="addInfo.universityAddress" ></el-input>
        </el-form-item>
        <el-form-item label="公告" >
          <el-input v-model="addInfo.notice" ></el-input>
        </el-form-item>
        <el-form-item label="高校负责人" >
          <el-input v-model="addInfo.universityDirector" ></el-input>
        </el-form-item>
        <el-form-item label="负责人手机号" >
          <el-input v-model="addInfo.directorPhone" ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click=addUniversity>确 定</el-button>
      </div>
     </el-dialog>
     <el-dialog title="编辑高校信息" align="left" :visible.sync="dialogForm2Visible">
      <el-form :model="editInfo" label-width="100px">
        <el-form-item label="高校名称" >
          <el-input v-model="editInfo.universityName" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="高校地址" >
          <el-input v-model="editInfo.universityAddress" ></el-input>
        </el-form-item>
        <el-form-item label="公告" >
          <el-input v-model="editInfo.notice" ></el-input>
        </el-form-item>
        <el-form-item label="高校负责人" >
          <el-input v-model="editInfo.universityDirector" ></el-input>
        </el-form-item>
        <el-form-item label="负责人手机号" >
          <el-input v-model="editInfo.directorPhone" ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogForm2Visible = false">取 消</el-button>
        <el-button type="primary" @click=Edit>确 定</el-button>
      </div>
     </el-dialog>
     <el-table
       stripe
        v-loading="listLoading"
        :row-style="{height:'45px'}"
        :cell-style="{padding:'0px'}"
        style="font-size: 14px;width: 100%"
        :header-cell-style="{background:'#eef1f6',color:'#606266'}"
        :data= universityManagementTable >
        <el-table-column
          type="index"
          align="center"
          label="序号"
          width="60">
        </el-table-column>
        <el-table-column
          align="center"
          prop="universityName"
          label="高校名称"
          width="140"
          :show-overflow-tooltip='true' >
        </el-table-column>
        <el-table-column
          align="center"
          prop="universityAddress"
          label="高校地址"
          width="200"
          :show-overflow-tooltip='true'>
        </el-table-column>
        <el-table-column
          align="center"
          prop="notice"
          label="学校公告"
          width="140"
          :show-overflow-tooltip='true' >
        </el-table-column>
        <el-table-column
          align="center"
          prop="universityDirector"
          label="高校负责人"
          width="100">
        </el-table-column>
        <el-table-column
          align="center"
          prop="directorPhone"
          label="负责人手机号"
          width="120">
        </el-table-column>
<!--        <el-table-column-->
<!--         align="center"-->
<!--         prop="universityStatus"-->
<!--         label="注册验证"-->
<!--         width="100">-->
<!--         <template slot-scope="scope">-->
<!--           <el-tag v-if=" scope.row.universityStatus === 1" type="success" effect="dark">使用中</el-tag>-->
<!--           <el-tag v-else-if="scope.row.universityStatus === 0"  >未开启</el-tag>-->
<!--         </template>-->
<!--        </el-table-column>-->
        <el-table-column
          align="center"
          prop="createTime"
          label="创建时间"
          width="200"
          :show-overflow-tooltip='true' >
        </el-table-column>
        <el-table-column  align="center" label="设置">
          <template slot-scope="scope">
            <span v-if="GLOBAL.global_limit.includes('8')">
            <el-button
              size="mini"
              @click="handleEdit(scope.row)">编辑</el-button>
            </span>
            <span v-if="GLOBAL.global_limit.includes('9')">
            <el-button
              size="mini"
              type="danger"
              @click="Delete( scope.row)">删除</el-button>
            </span>
          </template>
        </el-table-column>
     </el-table>
     <div class="el-pagination">
       <el-pagination
         @size-change="handleSizeChange"
         @current-change="handleCurrentChange"
         :current-page="queryInfo.pageNum"
         :page-sizes="[5, 8, 10, 15]"
         :page-size="queryInfo.pageSize"
         :total="total"
         layout="total, sizes, prev, pager, next, jumper">
       </el-pagination>
     </div>
  </div>
</template>

<script>
 export default {
   name:'universityManagement',
   data() {
    return {
      universityManagementTable: [],
      queryInfoCon:{
        universityName:null,
        universityDirector:null,
        universityStatus:1,
        filterDates:["",""],
      },
      queryInfo:{
        universityName:null,
        universityDirector:null,
        universityStatus:1,
        filterDates:["",""],
        pageNum: 1,
        pageSize: 10
      },
      addInfo:{
        universityName:null,
        universityAddress:null,
        universityStatus:1,
        notice:null,
        universityDirector:null,
        directorPhone:null,
        createTime:null
      },
      editInfo:{
        id:null,
        universityName:null,
        universityAddress:null,
        universityStatus:1,
        notice:null,
        universityDirector:null,
        directorPhone:null,
        createTime:null
      },
      delInfo:{
        id:null
      },
      dialogFormVisible: false,
      dialogForm2Visible: false,
      noTime:null,
      total: 0,
      directorList: [],
      statusList: [{
        label:'使用中',
        value: 1
      }, {
        label:'未开启',
        value: 0
      }],
    }
   },
   created() {
     this.initData();
     this.getTime()
   },
   methods: {
     //获取当前时间
     getTime(){
       var today = new Date()
       setInterval(()=>{
         this.nowTime = (today.getFullYear()) +"-" + (today.getMonth() + 1 ) + "-" + today.getDate() ;
       },1000)
     },
     //提交查询信息
     initData() {
         if(this.queryInfo.filterDates==null)
             this.queryInfo.filterDates=["",""]
         if(this.queryInfo.universityDirector=="")
             this.queryInfo.universityDirector=null
         if(this.queryInfo.universityName!=this.queryInfoCon.universityName||this.queryInfo.universityDirector!=this.queryInfoCon.universityDirector
             ||this.queryInfo.universityStatus!=this.queryInfoCon.universityStatus||this.queryInfo.filterDates!=this.queryInfoCon.filterDates){
             this.queryInfo.pageNum=1
             this.queryInfoCon.universityName=this.queryInfo.universityName
             this.queryInfoCon.universityDirector=this.queryInfo.universityDirector
             this.queryInfoCon.universityStatus=this.queryInfo.universityStatus
             this.queryInfoCon.filterDates=this.queryInfo.filterDates
         }

       var allData
       this.$axios.post("managementSystem/university/find",this.queryInfo)
         .then(data => {
           if (data.status != 200) {
             this.$message.error('服务出错' + data.status);
             // this.$message(fgf{
             //   message:'服务错误',
             //   type:'warn'
             // });
           } else {
             if (data.data.errorCode == '200') {
               allData = data.data
               console.log(allData.errorMsg)
               this.universityManagementTable=allData.universityManagementTable
               this.total=allData.totalNum
               this.directorList=allData.directorList
             }
           }
         })
     },
     //监听 页面尺寸 改变
     handleSizeChange (newSize) {
       this.queryInfo.pageSize = newSize
       this.initData()
     },
     // 监听 页码值 改变的事件
     handleCurrentChange (newPage) {
       // console.log(newPage)
       this.queryInfo.pageNum = newPage
       this.initData()
     },
     handleEdit(row) {  //进入编辑表单
       this.editInfo.id=row.id    //直接用this.editInfo=row 传会有问题
       this.editInfo.universityName=row.universityName
       this.editInfo.universityAddress=row.universityAddress
       this.editInfo.universityStatus=row.universityStatus
       this.editInfo.universityDirector=row.universityDirector
       this.editInfo.notice=row.notice
       this.editInfo.directorPhone=row.directorPhone
       this.editInfo.createTime=row.createTime
       this.dialogForm2Visible = true
     },
     Edit(){  //提交编辑内容
       this.dialogForm2Visible = false
       this.$axios.post("managementSystem/university/edit",this.editInfo)
         .then(data => {
           if (data.status != 200) {
             this.$message.error('服务出错' + data.status);
             // this.$message(fgf{
             //   message:'服务错误',
             //   type:'warn'
             // });
           } else {
             if (data.data.errorCode == '200') {
               console.log(data.data.errorMsg)
               this.$message({
                 type: 'success',
                 message: '修改成功!'
               })
               this.initData()
             }
           }
         })
     },
     Delete( row) {
       this.$confirm('此操作将永久删除该高校, 是否继续?', '提示', {
         confirmButtonText: '确定',
         cancelButtonText: '取消',
         type: 'danger',
         center: true
       }).then(() => {
         this.delInfo.id = row.id
         this.$axios.post("managementSystem/university/delete",this.delInfo)
           .then(data => {
             if (data.status != 200) {
               this.$message.error('服务出错' + data.status);
               // this.$message(fgf{
               //   message:'服务错误',
               //   type:'warn'
               // });
             } else {
               if (data.data.errorCode == '200') {
                 console.log("删除表项：", this.delInfo.id, data.data.errorMsg)
                 this.initData()
                 }
               }
           })
         this.$message({
           type: 'success',
           message: '高校删除成功!'
         })
       }).catch(() => {
         this.$message({
           type: 'info',
           message: '已取消删除'
         });
       });
     },
     addChoose(){ //每次点击新增先清空表单
       this.addInfo={
         universityName:null,
         universityAddress:null,
         universityStatus:1,
         notice:null,
         universityDirector:null,
         directorPhone:null,
         createTime:null
       }
       this.dialogFormVisible = true
     },
     addUniversity(){
       this.getTime()
       this.addInfo.createTime=this.nowTime
       var allData
       this.$axios.post("managementSystem/university/insert",this.addInfo)
         .then(data => {
           if (data.status != 200) {
             this.$message.error('服务出错' + data.status);
             // this.$message(fgf{
             //   message:'服务错误',
             //   type:'warn'
             // });
           } else {
             if (data.data.errorCode == '200') {
               allData=data.data
               console.log(allData.errorMsg)
               this.$message({
                 type: 'success',
                 message: '添加成功!'
               })
               this.dialogFormVisible=false;
               this.initData()
             }
           }
         })
     },
  }

 }

</script>

<style scoped>

</style>
